﻿using PlatformUW.Contracts;
using PlatformUW.EntityFramework.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlatformUW.EntityFramework
{
    public class RepositoryWrapper : IRepositoryWrapper
    {
        /// <summary>
        /// 玩家仓储接口的实现
        /// </summary>
        private IPlayerRepository _player;
        public IPlayerRepository Player
        {
            get => _player ??= new PlayerRepository(_repositoryContext);
        }

        /// <summary>
        /// 角色仓储接口的实现
        /// </summary>
        private ICharacterRepository _character;
        public ICharacterRepository Character
        {
            get => _character ??= new CharacterRepository(_repositoryContext);
        }

        /// <summary>
        /// 传感器仓储接口的实现
        /// </summary>
        private ISensorRepository _sensor;
        public ISensorRepository Sensor
        {
            get => _sensor ??= new SensorRepository(_repositoryContext);
        }       
        

        private readonly PlatformDBContext _repositoryContext;

        /// <summary>
        /// 仓储包装类的构造函数
        /// </summary>
        /// <param name="_repositoryContext"></param>
        public RepositoryWrapper(PlatformDBContext _repositoryContext)
        {
            this._repositoryContext = _repositoryContext;
        }

        /// <summary>
        /// 保存更改到数据库的异步方法
        /// </summary>
        /// <returns></returns>
        public async Task<int> SaveAsync()
        {
            return await _repositoryContext.SaveChangesAsync();
        }
    }
}
